/* Copyright 2012 Dustin Mitchell <dmmitche [at] gmail [dot] com>
 *
 * Licensed under the GPLv3.  See included LICENSE.txt for full details.
 */

#ifndef __MESSAGE_QUEUE__
#define __MESSAGE_QUEUE__

#include <pthread.h>

#include "hash.h"
#include "message_handler.h"
#include "messages.h"

struct message_queue
{
  pthread_mutex_t sync;
  struct hash handlers;
};

int message_queue_create (struct message_queue *queue);

void message_queue_destroy (struct message_queue *queue);

int message_queue_register_handler (struct message_queue *queue,
  struct message_handler *handler, int msg_type);

int message_queue_register_handler_multi (struct message_queue *queue,
  struct message_handler *handler, int *msg_types, size_t n_types);

int message_queue_unregister_handler (struct message_queue *queue,
  struct message_handler *handler, int msg_type);

int message_queue_unregister_handler_all (struct message_queue *queue,
  struct message_handler *handler);

int message_queue_post (struct message_queue *queue, const union message *msg);

#endif /* __MESSAGE_QUEUE__ */
